<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2017/1/12
  Time: 15:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://"
          + request.getServerName() + ":" + request.getServerPort()
          + path + "/";
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title></title>
  <link rel="stylesheet" type="text/css" href="<%=basePath%>css/easyui.css" />
  <link rel="stylesheet" type="text/css" href="<%=basePath%>css/icon.css" />
  <script type="text/javascript" src="<%=basePath%>js/jquery.min.js"></script>
  <script type="text/javascript" src="<%=basePath%>js/jquery.easyui.min.js"></script>
  <script type="text/javascript" src="<%=basePath%>js/easyui-lang-zh_CN.js"></script>
  <script type="text/javascript" src="<%=basePath%>js/json2.js"></script>
</head>
<body>
  <div id="Test" class="easyui-layout" fit="true">
    <div id="center" region="center" style="background:#eee; overflow:hidden;border:0px;">
     <table id="dataSource_grid" toolbar = "#toolbar" fitColumns="true" fit="true"  style="width:auto;height:50%" ></table>
    </div>
    <div id="toolbar">
      <table>
        <tr>
         <td><a id="refresh " class="easyui-linkbutton" title="刷新" iconCls="icon-reload" plain="true" onclick="refresh()">刷新</a></td>
          <td><div class="datagrid-btn-separator"></div></td>
          <td> <label  style="font-size:14px;height: 20px">起始位置:</label></td>
          <td>   <input id="firstId"type="text" class="easyui-numberbox" style="width: 80px;height:20px" data-options="min:0,precision:0"/></td>
          <td> <label style="font-size:14px;height: 20px">结束位置:</label></td>
          <td><input id="endId"type="text" class="easyui-numberbox" style="width: 80px;height:20px" data-options="min:0,precision:0"/></td>
          <%--<td><div class="datagrid-btn-separator"></div></td>--%>
          <td> <a id="find" class="easyui-linkbutton" title="查询" iconCls="icon-add" plain="true" onclick="findId()">查询</a></td>
        </tr>
    </div>
  </div>
</body>

  <script type="text/javascript">


    var dataGrid,tatol,pagenum,offset,srcId,tabName,uid;
    var firstId = null;var endId = null;
    var resltUrlData = getUrlData();

    pagenum =25;
    offset = 1;
        $('#dataSource_grid').datagrid({
        title: '数据查看'+': '+resltUrlData["tabName"],
        iconCls: 'icon-save',
        width: 700,
        height: 200,
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        fitColumns: true,
        singleSelect: true
      });
      function selectTab(){
        srcId = resltUrlData["srcId"];
        tabName = resltUrlData["tabName"];
        uid = resltUrlData["uid"];
        $.ajax({
          url: '<%=basePath%>selectTabController/selectTab?newDate=' + new Date(),//任务数据请求
          type: 'post',
          data: {limit: pagenum, page: 1, srcId: srcId, tabName: tabName, uid: uid,firstId:firstId,endId:endId},
          timeout: 20000,
          success: function (res) {
            if(res.code == 0) {
              tatol = res.data.total;
              var val = res.data.resultData;
              var column = res.data.resultLie;
              $('#dataSource_grid').datagrid({
                data: val,
                columns: [column],
              });
              $('#dataSource_grid').datagrid('getPager').pagination({//分页对象
                pageSize: pagenum,
                total: res.data.total,
                pageNumber: 1,
                pageList: [25, 50, 100],
                onSelectPage: function (pageNumber, pageSize) {
                  offset = pageNumber;
                  pagenum = pageSize;
                  var param = {page: pageNumber, limit: pagenum, srcId: srcId, tabName: tabName, uid: uid,firstId:firstId,endId:endId}
                  loadPages(param);
                }
              });
            }else{
              $.messager.alert('提示',"请求失败！");
            }
          }
        });
      }
      selectTab(); // 初始化
   // });

    /**分页加载对比记录数据**/
    function loadPages(param){
      $.ajax({
        url:'<%=basePath%>selectTabController/selectTab',
        type:'post',
        data:param,
        timeout:20000,
        success:function (res) {
          console.log(res)
          if (res.code == 0) {
            $('#dataSource_grid').datagrid({
              data: res.data.resultData
            });
            $('#dataSource_grid').datagrid("loaded");
            $('#dataSource_grid').datagrid('getPager').pagination({//分页对象
              pageSize: pagenum,
              total: res.data.total,
              pageNumber: param.page,
              pageList: [25, 50, 100],
              onSelectPage: function (pageNumber, pageSize) {
                pagenum = pageSize;
                var param = {
                  page: pageNumber,
                  limit: pageSize,
                  srcId: srcId,
                  tabName: tabName,
                  uid: uid,
                  firstId: firstId,
                  endId: endId
                };
                loadPages(param);
              },
            });
          } else {
            $.messager.alert('提示',"请求失败！");
          }
        }
      });
    }
    //点击查询功能，根据id查询数据
  function findId(){

    firstId = $('#firstId').numberbox('getValue');
    endId = $('#endId').numberbox('getValue');
    selectTab();
  }
  function refresh(){ //刷新
    selectTab();
  }

    //通过请求的url,得到参数
  function getUrlData(){
    str =  location.href;
    var num=str.indexOf("?")
    str=str.substr(num+1)

    var arr = str.split("&");//inputT=144&rsv_sug3=18

    var result = {};
    for(var index in arr){
      var in_arr = arr[index].split("=");
      result[in_arr[0]] = in_arr[1];
    }
    return result;
  }
</script>
</html>
